package com.fancylargo.crowd.controller;

import java.util.Arrays;
import java.util.Map;

import com.fancylargo.crowd.entity.UmsMemberEntity;
import com.fancylargo.crowd.feign.CouponFeignService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.fancylargo.crowd.entity.UmsMemberCollectSpuEntity;
import com.fancylargo.crowd.service.UmsMemberCollectSpuService;
import com.fancylargo.crowd.common.utils.PageUtils;
import com.fancylargo.crowd.common.Result.Result;

/**
 * 会员收藏的商品
 *
 * @author chaigq
 * @email 15532050839@163.com
 * @date 2020-07-05 19:38:42
 */

// 动态刷新配置注解
@RefreshScope
@RestController
@RequestMapping("crowd/umsmembercollectspu")
public class UmsMemberCollectSpuController {
    @Autowired
    private UmsMemberCollectSpuService umsMemberCollectSpuService;

    @Autowired
    CouponFeignService couponFeignService;

    // 获取配置中的变量
    @Value("${member.name}")
    private String name;

    @RequestMapping("/test")
    public Result testprotis() {

        return Result.ok().put("member.name", name);
    }

    @RequestMapping("/coupons")
    public Result test() {

        UmsMemberEntity umsMemberEntity = new UmsMemberEntity();
        umsMemberEntity.setNickname("测试会员服务调用");
        Result coupon = couponFeignService.membercoupons();
        return Result.ok().put("member", umsMemberEntity).put("coupon", coupon.get("coupon"));
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("crowd:umsmembercollectspu:list")
    public Result list(@RequestParam Map<String, Object> params) {
        PageUtils page = umsMemberCollectSpuService.queryPage(params);

        return Result.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    //@RequiresPermissions("crowd:umsmembercollectspu:info")
    public Result info(@PathVariable("id") Long id) {
        UmsMemberCollectSpuEntity umsMemberCollectSpu = umsMemberCollectSpuService.getById(id);

        return Result.ok().put("umsMemberCollectSpu", umsMemberCollectSpu);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("crowd:umsmembercollectspu:save")
    public Result save(@RequestBody UmsMemberCollectSpuEntity umsMemberCollectSpu) {
        umsMemberCollectSpuService.save(umsMemberCollectSpu);

        return Result.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("crowd:umsmembercollectspu:update")
    public Result update(@RequestBody UmsMemberCollectSpuEntity umsMemberCollectSpu) {
        umsMemberCollectSpuService.updateById(umsMemberCollectSpu);

        return Result.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("crowd:umsmembercollectspu:delete")
    public Result delete(@RequestBody Long[] ids) {
        umsMemberCollectSpuService.removeByIds(Arrays.asList(ids));

        return Result.ok();
    }

}
